﻿using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using log4net.Config;
using System.IO;
using RouterControl.IO;

namespace RouterControl.WhsAddIn.Logging
{
	public sealed class LogFactory
	{
		private static LogFactory _instance = new LogFactory();
		private ILog _log;

		public static LogFactory Instance
		{
			get { return _instance; }
		}

		public ILog GetLog<T_Class>() where T_Class: class
		{
			return LogManager.GetLogger(typeof(T_Class));
		}

		public ILog GetLog(Type t)
		{
			if (t == null)
				throw new ArgumentNullException("t");

			return LogManager.GetLogger(t);
		}

		private LogFactory()
		{
			var fi = new FileInfo(Whs.Properties.Constants.Log4NetConfigPath);

			if (!fi.Exists)
				throw new FileNotFoundException(fi.FullName);

			// configure
			XmlConfigurator.Configure(fi);

			// initialize
			_log = GetLog<LogFactory>();

			_log.Info("-------------------------------------------------------------- ROUTER CONTROL --------------------------------------------------------------");

            _log.Info("Instance ID: " + Whs.RouterControlRegistry.GetInstanceId());

			_log.Info("Windows Home Server version: " + System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetEntryAssembly().Location).FileVersion);

			// log header
			RouterControlVersion.LogVersion();
		}
	}
}
